package com.yanfan.zutai.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.zutai.aop.SysInitData;
import com.yanfan.zutai.aop.SysInitUpdateData;
import com.yanfan.zutai.aop.SysQueryData;
import com.yanfan.zutai.domain.BDeviceJs;
import com.yanfan.zutai.service.IBDeviceJsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 脚本管理Controller
 *
 * @author ruoyi
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/zutai/bDeviceJs")
public class BDeviceJsController extends BaseController {
    @Autowired
    private IBDeviceJsService bDeviceJsService;

    /**
     * 查询脚本管理列表
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:list')")
    @GetMapping("/list")
    @SysQueryData
    public TableDataInfo list(BDeviceJs bDeviceJs) {
        startPage();
        List<BDeviceJs> list = bDeviceJsService.selectBDeviceJsList(bDeviceJs);
        return getDataTable(list);
    }

    /**
     * 导出脚本管理列表
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:export')")
    @Log(title = "脚本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BDeviceJs bDeviceJs) {
        List<BDeviceJs> list = bDeviceJsService.selectBDeviceJsList(bDeviceJs);
        ExcelUtil<BDeviceJs> util = new ExcelUtil<BDeviceJs>(BDeviceJs.class);
        util.exportExcel(response, list, "脚本管理数据");
    }

    /**
     * 获取脚本管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bDeviceJsService.selectBDeviceJsById(id));
    }

    /**
     * 新增脚本管理
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:add')")
    @Log(title = "脚本管理", businessType = BusinessType.INSERT)
    @PostMapping
    @SysInitData
    public AjaxResult add(@RequestBody BDeviceJs bDeviceJs) {
        return toAjax(bDeviceJsService.insertBDeviceJs(bDeviceJs));
    }

    /**
     * 修改脚本管理
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:edit')")
    @Log(title = "脚本管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @SysInitUpdateData
    public AjaxResult edit(@RequestBody BDeviceJs bDeviceJs) {
        return toAjax(bDeviceJsService.updateBDeviceJs(bDeviceJs));
    }

    /**
     * 删除脚本管理
     */
    //@PreAuthorize("@ss.hasPermi('ghxx:bDeviceJs:remove')")
    @Log(title = "脚本管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bDeviceJsService.deleteBDeviceJsByIds(ids));
    }
}
